<?php

/**
 *	Common methods to every CRUD action 
 */
abstract class Cms_Abstract
{
	protected $_adapter;
	
	public function setCms(Cms_Adapter_Abstract $action, array $params)
	{
		$action->setTable($params['table'])
			->setSchema($params['schema'])
			->setDatabase($params['database']);
		
		return $this->_setAdapter($action);
	}
	
	private function _setAdapter($adapter)
	{
		$this->_adapter = $adapter;
		return $this;
	}
	
	public function getAdapter() {
		return $this->_adapter;
	}
	
	public function matchColumnsToPost($nms, $postNm)
	{
		foreach($nms as $key => $nm) {
			foreach($postNm as $selNm)
			{
				if(isset($selNm['info']))
				{
					$infoNm = $nm['info']['schema'].'.'.$nm['info']['table'];
					$infoSel = $selNm['info']['schema'].'.'
						.$selNm['info']['table'];

					if($infoNm == $infoSel) {
						$nms[$key]['data'][] = $selNm['columns'];
					}
				}
			}
		}
		
		return $nms;
	}
	
	protected function _request()
	{
		return Zend_Controller_Front::getInstance()->getRequest();
	}
	
	protected function _getParam($param, $default = null)
	{
		return $this->_request()->getParam($param, $default);
	}
	
	protected function _getParams()
	{
		return $this->_request()->getParams();
	}
	
	protected function _isPost()
	{
		return $this->_request()->isPost();
	}
	
	protected function _getPost($index = null, $default = null)
	{
		return $this->_request()->getPost($index, $default);
	}
}